package tests;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import junit.framework.TestCase;

public class FOSWriterTest extends TestCase {
	private String fileName="/Users/Maco/Desktop/pruebasSeg/file1.txt";
	private String text1="One";
	private String text2="two";
	private String text3="three";
	private String text4="four";

	public void testWriteString() {
		try {
			FileOutputStream f=new FileOutputStream(this.fileName);
			f.write(this.text1.getBytes());
			f.write(this.text2.getBytes());
			f.close();
			FileInputStream fi=new FileInputStream(this.fileName);
			byte[] b=new byte[fi.available()];
			fi.read(b);
			fi.close();
			String read=new String(b);
			assertTrue("Esperado: " + this.text1 + this.text2 + "; obtenido: " + read, read.equals(this.text1 + this.text2));
		} catch (IOException e) {
			fail("Not expected: " + e.toString());
		}
	}

	public void testWriteStringIntInt() {
		try {
			FileOutputStream f=new FileOutputStream(this.fileName);
			f.write(this.text1.getBytes(), 0, this.text1.length());
			f.write(this.text2.getBytes(), 0, this.text2.length());
			f.write(this.text3.getBytes(), 0, this.text3.length());
			f.write(this.text4.getBytes(), 0, this.text4.length());
			f.close();
			FileInputStream fi=new FileInputStream(this.fileName);
			byte[] b=new byte[fi.available()];
			fi.read(b);
			fi.close();
			String readed=new String(b);
			assertTrue("Esperado: " + this.text1 + this.text2+this.text3 + this.text4 + "; obtenido: " + readed, readed.equals(this.text1 + this.text2+this.text3 + this.text4));
		} catch (IOException e) {
			fail("Not expected: " + e.toString());
		}
	}

/*	public void testFailAposta() {
		try {
			FileOutputStream f=new FileOutputStream(this.fileName);
			f.write(this.text1.getBytes(), 0, this.text1.length());
			f.write(this.text2.getBytes(), 0, this.text2.length());
			f.close();
			fail("Fail aposta");
		}
		catch (Exception e) {
		}
	}
	
	private Object nulo=null;
	public void testNullAposta() {
		try {
			FileOutputStream f=new FileOutputStream(this.fileName);
			f.write(this.text1.getBytes(), 0, this.text1.length());
			f.write(this.text2.getBytes(), 0, this.text2.length());
			f.close();
		}
		catch (Exception e) {
		}
		nulo.toString();
	}*/
}
